import axios from 'axios';
import store from '../../redux/store';
axios.defaults.timeout = 5000;
axios.defaults.baseURL = 'http://47.97.101.38:8080/backend_maven';

// 添加请求拦截器
axios.interceptors.request.use(
    function (config) {
        const token = store.getState().login.token;
        if (!config || !config.headers) return config;
        // 携带token
        config.headers['Authorization'] = token;
        return config;
    },
    function (error) {
        // 对请求错误做些什么
        return Promise.reject(error);
    },
);

// 定义返回数据的通用接口
interface ResponseData<T> {
    result: {
        code: number;
        msg: string;
    };
    data?: T;
}

export default axios;
export { ResponseData };
